//
//  XiaDanViewController.m
//  XiangMu
//
//  Created by 康世标 on 15/7/21.
//  Copyright (c) 2015年 康世标. All rights reserved.
//

#import "XiaDanViewController.h"

@interface XiaDanViewController ()

@end

@implementation XiaDanViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    self.tabBarController.tabBar.hidden=YES;
    self.title=@"下单";
    UIButton*fanHuiBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    fanHuiBtn.frame = CGRectMake(20, 20, 10, 20);
    
    [fanHuiBtn addTarget:self action:@selector(fanhui) forControlEvents:UIControlEventTouchUpInside];
    
    [fanHuiBtn setBackgroundImage:[UIImage imageNamed:@"fanhui"] forState:UIControlStateNormal];
    
    UIBarButtonItem*barFanHui = [[UIBarButtonItem alloc]initWithCustomView:fanHuiBtn];
    self.navigationItem.leftBarButtonItem = barFanHui;
    
    

    [self.shiFuKuangBtn setBackgroundColor:CL_00cc85];

    [self.shiFuKuangBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [self.tiJiaoDingDanBtn setBackgroundColor:CL_00cc85];
    [self.tiJiaoDingDanBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    
    self.tableView1.separatorColor = [UIColor clearColor];
  
    _p=[[PickView alloc]initWithFrame:CGRectMake(0, kScreenH, kScreenW, 0)];
    _p.delegate=self;
    
    [self.view addSubview:_p];
    
    self.tableView1.backgroundColor = CL_efeff4;

    hud =[MBProgressHUD showHUDAddedTo:self.view animated:YES];
    hud.labelText = @"数据加载中";
    
    
    [self HuLiXinXiCaiDan];
    self.alerViewindex =1;

}
//护理信息
- (void)HuLiXinXiCaiDan{
    
    long ID =[[[NSUserDefaults standardUserDefaults]objectForKey:@"ID"] longValue];
    
    [QingQiuShuJu getHuLixinxi:@(ID) carerId:@([[self.dic valueForKey:@"id"] longValue]) Blokc:^(NSDictionary *dic, BOOL isOK)
    {
        
        if (isOK) {
                self.huLiDic = [dic mutableCopy];
            
           [self jiaGeChaXun];
           [self.tableView1 reloadSections:[NSIndexSet indexSetWithIndex:2] withRowAnimation:UITableViewRowAnimationFade];
            
            hud.hidden = YES;
            
        }
        else{
            
            hud.mode = MBProgressHUDModeText;
            hud.labelText = [dic valueForKey:@"msg"];
            
            [hud hide:YES afterDelay:1];
            
        }
    
        
        
        
    }];
    
    
}
//下单页面查询价格
- (void)jiaGeChaXun{
    
    
    NSArray * leiXingArr =[self.huLiDic valueForKey:@"carerTypes"];
    NSArray * xingBieArr =[self.huLiDic valueForKey:@"carerWays"];
    NSArray * tiZhongArr =[self.huLiDic valueForKey:@"weightTypes"];
    NSArray * timerArr   =[self.huLiDic valueForKey:@"timeTypes"];
    int leiXing = [[[leiXingArr objectAtIndex:0] valueForKey:@"carerTypeId"] intValue];
    int xingBie = [[[xingBieArr objectAtIndex:0] valueForKey:@"hcType"] intValue];
    int tiZhong = [[[tiZhongArr objectAtIndex:0]valueForKey:@"weightTypeId"] intValue];
    int time = [[[timerArr objectAtIndex:0]valueForKey:@"timeTypeId"] intValue];
    int  carerId =[[self.dic valueForKey:@"id"] intValue];
    
    
    chaXinDic =[[NSMutableDictionary alloc]initWithCapacity:0];
    [chaXinDic setObject:@(carerId) forKey:@"carerId"];
    [chaXinDic setObject:@(xingBie) forKey:@"way"];
    [chaXinDic setObject:@(leiXing) forKey:@"type"];
    [chaXinDic setObject:@(tiZhong) forKey:@"heavy"];
    [chaXinDic setObject:@(time) forKey:@"time"];
    [self jiaGe];

}
- (void)jiaGe{
    
     hud.labelText = @"数据加载中";
    [QingQiuShuJu jieGeChaXun:chaXinDic block:^(NSDictionary *dic, BOOL isOK) {
        
        if (isOK) {
            
            
            if ([[dic valueForKey:@"status"] intValue]==200)
            {
                NSString * price = [NSString stringWithFormat:@"实付款:￥%@元",[[dic valueForKey:@"data"]valueForKey:@"price"]];
                
                hud.hidden = YES;
                [self.shiFuKuangBtn setTitle:price forState:UIControlStateNormal];
                hud.removeFromSuperViewOnHide = YES;
            }
            else{
                hud.mode = MBProgressHUDModeText;
                hud.labelText = [dic valueForKey:@"msg"];
                
                [hud hide:YES afterDelay:2];
               
                hud.removeFromSuperViewOnHide = YES;
                HuLiXinXiTableViewCell * cell = (HuLiXinXiTableViewCell *)[self.tableView1 cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:2]];
                
                UIButton * button = (UIButton *)[cell viewWithTag:self.buttonIndextag];
                [button setTitle:@"" forState:UIControlStateNormal];
                
            }
        }
        else{
            hud.mode = MBProgressHUDModeText;
            hud.labelText =@"网络连接错误";
            
            [hud hide:YES afterDelay:1];
           hud.removeFromSuperViewOnHide = YES;
        }
        
    }];
    
    
    
}
#pragma mark--UITableViewDataSource,UITableViewDelegate
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 1;
    
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    
    return 5;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    if (section==0) {
        return 0;
    }
    return 10.0f;
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return 0;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
//    个人资料
    if (indexPath.section==0) {
        GeRenZiLiaoTableViewCell*cell=[tableView dequeueReusableCellWithIdentifier:@"yi"];
        if (!cell) {
            cell =[[[NSBundle mainBundle]loadNibNamed:@"GeRenZiLiaoTableViewCell" owner:nil options:nil]lastObject];
        
        }
        cell.selectionStyle = UITableViewCellSelectionStyleNone;

        cell.lable1.text = [_dic objectForKey:@"realname"]==[NSNull null]?@"":[NSString stringWithFormat:@"%@ :",[_dic objectForKey:@"realname"]];
        
        cell.lable2.text = [NSString stringWithFormat:@"%@      护龄%@年",[_dic valueForKey:@"censusRegister"]==[NSNull null]?@"":[_dic valueForKey:@"censusRegister"],[_dic valueForKey:@"carerAge"]==[NSNull null]?@"":[_dic valueForKey:@"carerAge"]];
        //内容
        cell.lbale3.text = [_dic valueForKey:@"description"]==[NSNull null]?@"":[_dic valueForKey:@"description"];

        [cell.hedImagView sd_setImageWithURL:[NSURL URLWithString:[_dic valueForKey:@"headImg"]==[NSNull null]?@"http://img5.duitang.com/uploads/item/201405/17/20140517133100_5SBvs.png":[_dic valueForKey:@"headImg"]] placeholderImage:[UIImage imageNamed:@"like"]];
        
        NSString * url = [_dic valueForKey:@"certificateImg"];//==[NSNull null]?@"zhengjian":[_dic valueForKey:@"certificateImg"];
        
//        NSLog(@"---%@",url);
        [cell.button addTarget:self action:@selector(certificate:) forControlEvents:UIControlEventTouchUpInside];
        
        [cell.button sd_setBackgroundImageWithURL:[NSURL URLWithString:url] forState:UIControlStateNormal placeholderImage:[UIImage imageNamed:@"zhengjian"]];
        
        
        
        if ([[_dic valueForKey:@"state"] intValue]==1)
        {
            //闲
            cell.state.image = [UIImage imageNamed:@"idle"];
        }
        else{
            
            cell.state.image = [UIImage imageNamed:@"busy"];
        }
        

        
        return cell;
    }
//    用户评价
    else if (indexPath.section==1){
 
        YongHuPingjIaTableViewCell*cell=[tableView dequeueReusableCellWithIdentifier:@"er"];
        if (!cell) {
            cell =[[[NSBundle mainBundle]loadNibNamed:@"YongHuPingjIaTableViewCell" owner:nil options:nil]lastObject];
        }
        
        cell.lable2.text = [NSString stringWithFormat:@"(%@)", [_dic valueForKey:@"commentNum"]==[NSNull null]?@"":[_dic valueForKey:@"commentNum"]];
         cell.selectionStyle=UITableViewCellSelectionStyleNone;
        return cell;
        
    }
////    护理信息
    else if (indexPath.section==2)
    {
        HuLiXinXiTableViewCell*cell=[tableView dequeueReusableCellWithIdentifier:@"san"];
        if (!cell) {
            cell =[[[NSBundle mainBundle] loadNibNamed:@"HuLiXinXiTableViewCell" owner:nil options:nil]lastObject];

        }
       
        NSArray * leiXingArr =[self.huLiDic valueForKey:@"carerTypes"];
        NSArray * xingBieArr =[self.huLiDic valueForKey:@"carerWays"];
        NSArray * shiJianArr =[self.huLiDic valueForKey:@"decadeTypes"];
        NSArray * weightArr  =[self.huLiDic valueForKey:@"weightTypes"];
        NSArray * timeArr    =[self.huLiDic valueForKey:@"timeTypes"];
        if (leiXingArr.count!=0) {
            
            [cell.leiXingBen setTitle:[[xingBieArr objectAtIndex:0] valueForKey:@"carerWay"] forState:UIControlStateNormal];
        }
        
        if (xingBieArr.count!=0) {
            
            [cell.xingBieBtn setTitle:[[leiXingArr objectAtIndex:0]valueForKey:@"carerType"] forState:UIControlStateNormal];
        }
    
        if (shiJianArr.count!=0) {
            [cell.shiJianBtn setTitle:[[shiJianArr objectAtIndex:0] valueForKey:@"type"] forState:UIControlStateNormal];
        }
        
        if (weightArr.count!=0) {
            [cell.tiZhongBtn setTitle:[[weightArr objectAtIndex:0] valueForKey:@"weightType"] forState:UIControlStateNormal];
        }
        if (timeArr.count !=0) {
            
            [cell.xiaDanWenBtn setTitle:[NSString stringWithFormat:@"%@小时",[[timeArr objectAtIndex:0] valueForKey:@"timeType"]] forState:UIControlStateNormal];
            
        }
        NSString * str;
        
        if ([str isKindOfClass:[NSNull class]]) {
            
        }
        [cell.leiXingBen addTarget:self action:@selector(caiDanBtn:) forControlEvents:UIControlEventTouchUpInside];
        [cell.xingBieBtn addTarget:self action:@selector(caiDanBtn:) forControlEvents:UIControlEventTouchUpInside];
        [cell.shiJianBtn addTarget:self action:@selector(caiDanBtn:) forControlEvents:UIControlEventTouchUpInside];
        [cell.tiZhongBtn addTarget:self action:@selector(caiDanBtn:) forControlEvents:UIControlEventTouchUpInside];
        [cell.xiaDanWenBtn addTarget:self action:@selector(caiDanBtn:) forControlEvents:UIControlEventTouchUpInside];
        cell.selectionStyle=UITableViewCellSelectionStyleNone;
        return cell;
    }
     else if (indexPath.section==3)
     {
         XiaDanTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"si"];
         if (!cell) {
             cell=[[[NSBundle mainBundle]loadNibNamed:@"XiaDanTableViewCell" owner:nil options:nil]lastObject];
             
         }
         
         cell.selectionStyle = UITableViewCellSelectionStyleNone;
         
         [cell.xuanZeShiJianBtn setTitle:_timesData forState:UIControlStateNormal];
         
         [cell.xuanZeShiJianBtn addTarget:self action:@selector(xuanZeShiJianBtn1:) forControlEvents:UIControlEventTouchUpInside];
         return cell;

     }
    static NSString*strr=@"";
    PeiHuDiZhiXinXiTableViewCell*cell = [tableView dequeueReusableCellWithIdentifier:strr];
    
    if (!cell)
    {
        cell = [[[NSBundle mainBundle] loadNibNamed:@"PeiHuDiZhiXinXiTableViewCell" owner:nil options:nil] lastObject];
        
    }
        cell.selectionStyle=UITableViewCellSelectionStyleNone;
        NSDictionary * dic =[self.huLiDic valueForKey:@"userAddr"];
    
        cell.name.text =[dic valueForKey:@"name"]==[NSNull null]?@"":[dic valueForKey:@"name"];
        cell.tel.text =[dic valueForKey:@"tel"]==[NSNull null]?@"":[dic valueForKey:@"tel"];
        
        cell.addr.text =[dic valueForKey:@"addr"]==[NSNull null]?@"":[dic valueForKey:@"addr"];

    return cell;
    
    
    
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

-(void)fanhui{
    
    [self.navigationController popViewControllerAnimated:YES];
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.section==0)
    {
        NSString *str = [self.dic valueForKey:@"description"]==[NSNull null]?@"":[self.dic valueForKey:@"description"];
        
        CGRect rect = [str boundingRectWithSize:CGSizeMake(kScreenW-80, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:14]} context:nil];
        
        
        return 100+rect.size.height;
    }
    else if(indexPath.section==1)
    {
        return 50;
    }
    else if(indexPath.section==2)
    {
        return  254;
    }
    else if(indexPath.section==3)
    {
        return 83;
    }
    return 93;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
   
    if (indexPath.section==1)
    
    {
        YongHuPingJiaViewController*y=[[YongHuPingJiaViewController alloc]init];
        
        y.numberPage = [_dic valueForKey:@"commentNum"]== [NSNull null]?0:[[_dic valueForKey:@"commentNum"] intValue];
        
        y.carerId = [[_dic valueForKey:@"id"] intValue];
        
        [self.navigationController pushViewController:y animated:YES];
    }
    
    if (indexPath.section ==4) {
        
        DiZhiXuanZeViewController * diZhi = [[DiZhiXuanZeViewController alloc]init];
        
        diZhi.index = ^(NSDictionary *  index){
           
            [self.huLiDic setObject:index forKey:@"userAddr"];
           
            [self.tableView1 reloadSections:[NSIndexSet indexSetWithIndex:4] withRowAnimation:UITableViewRowAnimationFade];
            
        };
//
        [self.navigationController pushViewController:diZhi animated:YES];
        
    }
    
}
#pragma mark--提交订单
- (IBAction)TiJiaoDingDan:(id)sender {
 
    [self tiJiaoDingDan];
}
- (void)tiJiaoDingDan{
    
   
    
    NSMutableDictionary * dingDanDic =[[NSMutableDictionary
                                        alloc]initWithCapacity:0];
    HuLiXinXiTableViewCell * cell = (HuLiXinXiTableViewCell *)[self.tableView1 cellForRowAtIndexPath:[NSIndexPath indexPathForItem:0 inSection:2]];
    XiaDanTableViewCell * xCell = (XiaDanTableViewCell *)[self.tableView1 cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:3]];
    PeiHuDiZhiXinXiTableViewCell * pCell = (PeiHuDiZhiXinXiTableViewCell *)[self.tableView1 cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:4]];

    if ([cell.leiXingBen.titleLabel.text isEqualToString:@""]||cell.leiXingBen.titleLabel.text==nil)
    {
        
      [[[UIAlertView alloc]initWithTitle:nil message:@"请选择陪护类型" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil] show];
        return;
    }
    else if ([cell.xingBieBtn.titleLabel.text isEqualToString:@""]||cell.xingBieBtn.titleLabel.text==nil)
    {
        
    
    [[[UIAlertView alloc]initWithTitle:nil message:@"请选择陪护方式" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil] show];
        return;
    }
   else if ([cell.shiJianBtn.titleLabel.text isEqualToString:@""]||cell.shiJianBtn.titleLabel.text==nil)
   {
        
      
    [[[UIAlertView alloc]initWithTitle:nil message:@"请选择陪护时间" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil] show];
       return;
    }
   else if ([cell.tiZhongBtn.titleLabel.text isEqualToString:@""]||cell.tiZhongBtn.titleLabel.text==nil)
   {
        [[[UIAlertView alloc]initWithTitle:nil message:@"请选择体重" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil] show];
       return;
    }
   else if ([cell.xiaDanWenBtn.titleLabel.text isEqualToString:@""]||cell.xiaDanWenBtn.titleLabel.text==nil)
   {
           [[[UIAlertView alloc]initWithTitle:nil message:@"请选择下单单位" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil] show];
       return;
    
    }
    else if ([xCell.xuanZeShiJianBtn.titleLabel.text isEqualToString:@""]||xCell.xuanZeShiJianBtn.titleLabel.text==nil)
    {
        [[[UIAlertView alloc]initWithTitle:nil message:@"请选择开始时间" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles: nil] show];
        return;
        
    }
    else if ([pCell.name.text isEqualToString:@""]||pCell.name.text==nil){
        
        [[[UIAlertView alloc]initWithTitle:nil message:@"请选择地址" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles: nil] show];
        return;
    }

    hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    hud.labelText = @"数据加载中...";
    long userId = [[[NSUserDefaults standardUserDefaults]objectForKey:@"ID"] longValue];
    int carerId = [[self.dic valueForKey:@"id"] intValue];
    
     [dingDanDic setObject:@(userId) forKey:@"userId"];
     [dingDanDic setObject:@(carerId) forKey:@"carerId"];
     [dingDanDic setObject:cell.leiXingBen.titleLabel.text forKey:@"carerType"];
     [dingDanDic setObject:cell.tiZhongBtn.titleLabel.text forKey:@"weightType"];
     [dingDanDic setObject:cell.xiaDanWenBtn.titleLabel.text forKey:@"timeType"];
     [dingDanDic setObject:cell.shiJianBtn.titleLabel.text forKey:@"decadeType"];

    NSDictionary * dic =[self.huLiDic valueForKey:@"userAddr"];

     [dingDanDic setObject:[dic valueForKey:@"name"] forKey:@"cusName"];
     [dingDanDic setObject:@([dic valueForKey:@"age"]==[NSNull null]?0:[[dic valueForKey:@"age"] intValue]) forKey:@"cusAge"];
     [dingDanDic setObject:[dic valueForKey:@"sex"]==[NSNull null]?@"":[dic valueForKey:@"sex"] forKey:@"cusSex"];
     [dingDanDic setObject:[dic valueForKey:@"tel"]==[NSNull null]?@"":[dic valueForKey:@"tel"] forKey:@"cusTel"];
     [dingDanDic setObject:[dic valueForKey:@"addr"]==[NSNull null]?@"":[dic valueForKey:@"addr"] forKey:@"cusAddress"];
    
    NSArray * price = [self.shiFuKuangBtn.titleLabel.text componentsSeparatedByString:@"￥"];
    NSString * price1 = [price lastObject];
    
    NSArray * fires =[price1 componentsSeparatedByString:@"元"];
    
     [dingDanDic setObject:@([[fires firstObject] intValue])forKey:@"price"];
        
     [dingDanDic setObject:xCell.xuanZeShiJianBtn.titleLabel.text forKey:@"startTime"];
    
    [QingQiuShuJu chuanJianDingDan:dingDanDic block:^(NSDictionary *dic, BOOL isOK)
     {
         if (isOK) {
             
             if ([[dic valueForKey:@"status"] intValue]==200)
             {
                 TiJiaoDingDanViewController*t=[[TiJiaoDingDanViewController alloc]init];
                 t.dataDic = [dic valueForKey:@"data"];
                 [hud hide:YES];
                 [self.navigationController pushViewController:t animated:YES];

             }
             
             else{
                 
                 hud.mode = MBProgressHUDModeText;
                 hud.labelText = [dic valueForKey:@"msg"];
                 [hud hide:YES afterDelay:1.5];
             }
            
         }
         else{
             hud.mode = MBProgressHUDModeText;
             hud.labelText = @"网络连接错误";
             [hud hide:YES afterDelay:1.5];

         }
        
         hud.removeFromSuperViewOnHide = YES;
    }];
}
#pragma mark---选择陪护时间
-(void)xuanZeShiJianBtn1:(UIButton *)btn{
    
  //  _tiJiaoDingDanBtn.userInteractionEnabled=NO;
    [UIView animateWithDuration:.5 animations:^{
        if (iphone5x_4_0==1) {
             _p.frame=CGRectMake(0, kScreenH/2-40, kScreenW  , kScreenH/2);
        }
        if (iphone6_4_7==1) {
            
            _p.frame=CGRectMake(0, kScreenH/2, kScreenW  , kScreenH/2);
        }
        
        if (iphone6Plus_5_5==1) {
              _p.frame=CGRectMake(0, kScreenH/2+40, kScreenW  , kScreenH/2);
        }
        if (iphone4x_3_5==1) {
              _p.frame=CGRectMake(0, kScreenH/2-80, kScreenW  , kScreenH/2);
        }
        
    }];
   
    
}
#pragma mark--pickViewDelegate;
-(void)pickView:(PickView *)pickView btnClokc:(NSString *)riqi ShiJian:(NSString *)shijian Year:(NSString *)year IsOK:(BOOL)isok{
 //    [self.tableView1 reloadData];
    if (isok) {
        [UIView animateWithDuration:.5 animations:^{
            _p.frame=CGRectMake(0, kScreenH, kScreenW, kScreenH/2);
            
        }];
        
        _timesData = riqi;
        
        
        [self.tableView1 reloadSections:[NSIndexSet indexSetWithIndex:3] withRowAnimation:UITableViewRowAnimationFade];


    }
    else{
        [UIView animateWithDuration:.5 animations:^{
            _p.frame=CGRectMake(0, kScreenH, kScreenW, kScreenH/2);

        }];
        
    }
}
#pragma mark---查看证书
-(void)chaKanZhengShu:(UIButton *)btn{
    ChaKanZhengShuViewController*c=[[ChaKanZhengShuViewController alloc]init];
    [self.navigationController pushViewController:c animated:YES];
}

#pragma mark --- 护理信息

- (void)caiDanBtn:(UIButton *)sender{
    
    self.buttonIndextag = sender.tag;
    
    UIActionSheet * sheet = [[UIActionSheet alloc]initWithTitle:nil delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:nil otherButtonTitles: nil];
    NSArray * arr= [NSArray arrayWithObjects:@"carerWays",@"carerTypes",@"decadeTypes",@"weightTypes",@"timeTypes", nil];
//    timeTypeId
     NSArray * arr2= [NSArray arrayWithObjects:@"carerWay",@"carerType",@"type",@"weightType",@"timeType", nil];
    NSArray * arrs =[self.huLiDic valueForKey:[arr objectAtIndex:sender.tag-100]];
    
    
    if (sender.tag -100==1) {
        
        for (NSDictionary * dic in arrs) {
            
            //取出来陪护方式的ID 进行判断 陪护类型要展示什么
            
            int Id =[[[[self.huLiDic valueForKey:@"carerWays"]objectAtIndex:self.alerViewindex]valueForKey:@"hcType"]intValue];
            
            if (Id == [[dic valueForKey:@"hcType"] intValue]) {
                
                 [sheet addButtonWithTitle:[dic valueForKey:@"carerType"]];
            }
            
        }
    }
    else{
        for (NSDictionary *dic in arrs)
        {
            if (sender.tag-100==4)
             {
                 [sheet addButtonWithTitle:[NSString stringWithFormat:@"%@小时",[dic valueForKey:[arr2 objectAtIndex:sender.tag-100]]]];
             }
            else
            {
                 [sheet addButtonWithTitle:[dic valueForKey:[arr2 objectAtIndex:sender.tag-100]]];
            }
        }
    }
    
    
//      NSMutableArray * sArr= [[NSMutableArray alloc]initWithCapacity:0];
//    for (NSDictionary *dic in arrs) {
//        if (sender.tag-100==4) {
//              [sheet addButtonWithTitle:[NSString stringWithFormat:@"%@小时",[dic valueForKey:[arr2 objectAtIndex:sender.tag-100]]]];
//        }
//        else{
//            if (sender.tag-100==1) {
//                
////                NSArray * arr1= [self.huLiDic valueForKey:@"carerTypes"];
//               
//                for (NSDictionary *dic in arrs)
//                {
//                    
//                    if ([[[[self.huLiDic valueForKey:@"carerWays"]objectAtIndex:self.alerViewindex-1]valueForKey:@"hcType"]intValue]==[[dic valueForKey:@"hcType"] intValue])
//                    {
//                        
////                        [sArr addObject:[dic valueForKey:@"carerType"]];
//                        
//                        //                    NSLog(@"----%@",[dic valueForKey:@"carerType"]);
//                        [sheet addButtonWithTitle:[dic valueForKey:@"carerType"]];
//                    }
//                    
//                  
//                    
//                }
//            }
//            
//            else{
//              [sheet addButtonWithTitle:[dic valueForKey:[arr2 objectAtIndex:sender.tag-100]]];
//            }
//        }
//      
//        
//    }
    
    [sheet showInView:self.view];
}
#pragma mark -- UIActionSheetDelegate
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex{
    if (buttonIndex == 0) {
        
        return;
        
    }
   
    
    NSArray * arr= [NSArray arrayWithObjects:@"carerWays",@"carerTypes",@"decadeTypes",@"weightTypes",@"timeTypes", nil];
    NSArray * arr2= [NSArray arrayWithObjects:@"carerWay",@"carerType",@"type",@"weightType",@"timeType",nil];
 
    
    NSArray * arrs =[self.huLiDic valueForKey:[arr objectAtIndex:self.buttonIndextag-100]];
    NSDictionary * string = [arrs objectAtIndex:buttonIndex-1];
    
    HuLiXinXiTableViewCell * cell = (HuLiXinXiTableViewCell *)[self.tableView1 cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:2]];
    
    UIButton * button = (UIButton *)[cell viewWithTag:self.buttonIndextag];
//    if (self.buttonIndextag-100==4) {
//        [ button setTitle:[NSString stringWithFormat:@"%@小时",[string valueForKey:[arr2 objectAtIndex:self.buttonIndextag-100]]] forState:UIControlStateNormal];
//
//    }
//    else{
//        if (self.buttonIndextag-100==0) {
//            
//            NSLog(@"护理方式");
//            
//            UIButton * button1 = (UIButton *)[cell viewWithTag:1];
//            
//            NSArray * arr= [[self.huLiDic valueForKey:@"carerTypes"]objectAtIndex:0];
//            
//            [button1 setTitle:[[arr objectAtIndex:0] valueForKey:@"carerType"] forState:UIControlStateNormal];
//            
//            
//        }
      
//    }
    
    
    
    
    switch (self.buttonIndextag-100) {
        case 0:
        {
           
             self.alerViewindex =buttonIndex-1;
            [ button setTitle:[string valueForKey:[arr2 objectAtIndex:self.buttonIndextag-100]] forState:UIControlStateNormal];

            //方式
            int hcType =[[string valueForKey:@"hcType"] intValue];
            [chaXinDic setObject:@(hcType) forKey:@"way"];
            
            
            UIButton * btn = (UIButton *)[cell viewWithTag:1];
          
            NSArray * arr= [self.huLiDic valueForKey:@"carerTypes"];
            
            NSMutableArray * sArr= [[NSMutableArray alloc]initWithCapacity:0];
            for (NSDictionary * dic in arr) {
                
                if ([[[[self.huLiDic valueForKey:@"carerWays"]objectAtIndex:buttonIndex-1]valueForKey:@"hcType"]intValue]==[[dic valueForKey:@"hcType"] intValue])
                {
                    
                    [sArr addObject:dic];
                    
//                    NSLog(@"----%@",[dic valueForKey:@"carerType"]);
                    
                }
            }
//            NSLog(@"---%@",[sArr objectAtIndex:0]);
            
            [btn setTitle:[[sArr objectAtIndex:0] valueForKey:@"carerType"] forState:UIControlStateNormal];
            int typeId =[[[sArr objectAtIndex:0]valueForKey:@"carerTypeId"] intValue];
            
            [chaXinDic setObject:@(typeId) forKey:@"type"];
            
        }
            break;
        case 1:
        {  [ button setTitle:[string valueForKey:[arr2 objectAtIndex:self.buttonIndextag-100]] forState:UIControlStateNormal];

            int typeId =[[string valueForKey:@"carerTypeId"] intValue];
            
            [chaXinDic setObject:@(typeId) forKey:@"type"];
        }
            break;
        case 2:
        {
            [ button setTitle:[string valueForKey:[arr2 objectAtIndex:self.buttonIndextag-100]] forState:UIControlStateNormal];

        }
            break;
        case 3:
            
        {
         //体重
            int weightTypeId =[[string valueForKey:@"weightTypeId"] intValue];
            [chaXinDic setObject:@(weightTypeId) forKey:@"heavy"];
            [ button setTitle:[string valueForKey:[arr2 objectAtIndex:self.buttonIndextag-100]] forState:UIControlStateNormal];

        }
            break;
        case 4:
            //时间单位
        {    int timeTypeId =[[string valueForKey:@"timeTypeId"] intValue];
              [chaXinDic setObject:@(timeTypeId) forKey:@"time"];
            [ button setTitle:[NSString stringWithFormat:@"%@小时",[string valueForKey:[arr2 objectAtIndex:self.buttonIndextag-100]]] forState:UIControlStateNormal];

        }
            break;
        default:
            break;
    }
    
    hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    
    [self jiaGe];
    
}
#pragma mark -- 陪护是证书详情
- (void)certificate:(UIButton *)btn{
    
    Certificate *cert = [[Certificate alloc]init];
    
    NSString * url =[_dic valueForKey:@"certificateImg"];
    cert.url = url;
    
    [self.navigationController pushViewController:cert animated:YES];
    
}
/*c
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
